package com.takeaway.dao.daolmpl;

import com.takeaway.dao.daointerface.BookDao;
import com.takeaway.pojo.Book;
import com.takeaway.utils.JdbcUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 后台赖骏
 */
public class BookDaoImpl implements BookDao {
    @Override
    public int insert(Book book) throws Exception{
        return JdbcUtils.insert(book);
    }

    @Override
    public int delete(Class<Book> clz, String[] checkField, Object... factor) throws Exception{
        return JdbcUtils.delete(clz,checkField,factor);
    }

    @Override
    public int update(Book book) throws Exception{
        return JdbcUtils.update(book);
    }

    @Override
    public Book selectSingle(Book book, String[] checkFields, Object... factor) throws Exception{
        return (Book) JdbcUtils.selectSingle(book,checkFields,factor);
    }

    @Override
    public ArrayList<Book> selectMore(Class<Book> clz, int begin, int listNum) throws Exception{
        return (ArrayList<Book>) JdbcUtils.selectMore(clz,begin,listNum);
    }

    @Override
    public ArrayList<Book> selectMore(Class<Book> clz, String[] checkField, Object... factor) throws Exception{
        return (ArrayList<Book>) JdbcUtils.selectMore(clz,checkField,factor);
    }

    @Override
    public List<Book> selectBookManage(int shopId) throws Exception {
        String sql = "SELECT book.* FROM book,food,`user` " +
                "WHERE foodId = food.id AND shopId = ?"+
                " AND userId = user.id";
        return JdbcUtils.executeSelectList(Book.class, sql,shopId);
    }
}
